<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>定位SDK辅助定位</title>
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=wfSQ0h69XGW0C375EDuFiUVnbwn8MWGk"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=wfSQ0h69XGW0C375EDuFiUVnbwn8MWGk"></script>
    <style type="text/css">  
        html{height:100%}    
        body{height:100%;margin:0px;padding:0px}    
        #allmap{height:100%}    
    </style> 
</head>
<body>
    <!-- <div id="container"></div>  -->
    <div id="allmap"></div> 
    <!-- 浏览器定位 -->
    <!-- <script>
        var map = new BMapGL.Map("allmap");
        var point = new BMapGL.Point(116.331398,39.897445);
        map.centerAndZoom(point,12);
        var geolocation = new BMapGL.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                var mk = new BMapGL.Marker(r.point);
                map.addOverlay(mk);
                map.panTo(r.point);
                alert('[浏览器定位]您的位置：' + r.point.lng + ',' + r.point.lat);


                //逆地址解析
                //var map = new BMapGL.Map("container");      
                //map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);      
                // 创建地理编码实例      
                var myGeo = new BMapGL.Geocoder();      
                // 根据坐标得到地址描述    
                myGeo.getLocation(new BMapGL.Point(r.point.lng, r.point.lat), function(result){      
                    if (result){      
                    alert(result.address);
                    console.log("浏览器定位结果：")
                    console.log(r.point.lng+" "+ r.point.lat)
                    console.log(result.address)      
                    }      
                });


            }
            else {
                alert('failed' + this.getStatus());
            }        
        });
    </script> -->
    <!-- ip定位 -->
    <!-- <script>
        var map = new BMapGL.Map("allmap");
    var point = new BMapGL.Point(116.331398,39.897445);
    map.centerAndZoom(point,12);
    
    function myFun(result){
        console.log("打印result")
        console.log(result)
        var cityName = result.name;
        map.setCenter(cityName);
        alert("[ip定位]当前定位城市:" + cityName);
        console.log("ip地址：")
        console.log(cityName)
    }
    var myCity = new BMapGL.LocalCity();
    myCity.get(myFun); 
    </script> -->
    <!-- 定位SDK辅助定位 -->
    <script>
        var map = new BMapGL.Map("allmap");
        var point = new BMapGL.Point(116.331398,39.897445);
        map.centerAndZoom(point,12);
                
        var geolocation = new BMapGL.Geolocation();
        // 开启SDK辅助定位
        geolocation.enableSDKLocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                var mk = new BMap.Marker(r.point);
                //var mk = new map.Marker(r.point);
                map.addOverlay(mk);
                map.panTo(r.point);
                alert('[定位SDK辅助定位]您的位置：' + r.point.lng + ',' + r.point.lat);


                //逆地址解析
                //var map = new BMapGL.Map("container");      
                //map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 11);      
                // 创建地理编码实例      
                var myGeo = new BMapGL.Geocoder();      
                // 根据坐标得到地址描述    
                myGeo.getLocation(new BMapGL.Point(r.point.lng, r.point.lat), function(result){      
                    if (result){      
                    //alert(result.address);
                    console.log("[定位SDK辅助定位]定位结果：")
                    console.log(r.point.lng+" "+ r.point.lat)
                    console.log(result.address)  
                    alert('[定位SDK辅助定位]您的位置：' +result.address+' ' +r.point.lng + ',' + r.point.lat);
                    }      
                });
                










            }
            else {
                alert('failed' + this.getStatus());
            }        
        });
    </script>
</body>
</html>
